package com.itcodai.controller;

import com.alibaba.fastjson.JSONObject;
import com.itcodai.entity.JsonResult;
import com.itcodai.service.impl.TestService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author c-fanqj
 * @date 2023/5/17
 * @apiNote
 */
@RestController
@RequestMapping("/test")
public class TestController {

    //private final Logger logger = LoggerFactory.getLogger(this.getClass());
    private  static Logger logger = LoggerFactory.getLogger(TestController.class);

    @Resource
    private TestService testService;

    @RequestMapping("/testUser")
    public JsonResult testUser(@RequestBody JSONObject object) {
        logger.info("传入参数-{}", object);
        List<String> resultList = testService.test(object);
        return new JsonResult(resultList);
    }

    @RequestMapping("/mytest")
    public JsonResult mytest(String name) {
        logger.info("传入参数-{}", name);
        //System.out.println("811111111111111111111111111111188888888888888888888888888888888888");
        return new JsonResult("传入参数-" + name);
    }

    private static AtomicInteger atomicInteger = new AtomicInteger(0);
    public static void main(String[] args) {
        logger.info("atomicInteger-{}", atomicInteger.get());
        //logger.info("atomicInteger2-{}", atomicInteger.incrementAndGet());
        //logger.info("atomicInteger3-{}", atomicInteger.get());
        /*if(atomicInteger.incrementAndGet() % 2 == 0) {
            logger.info("atomicInteger4-{}", atomicInteger.get());
            //return;
        } else {
            logger.info("atomicInteger5-{}", atomicInteger.get());
        }*/
        for (int i = 0; i < 5; i++) {
            new Thread(() -> {
                for (int j = 0; j <100; j++) {
                    atomicInteger.incrementAndGet();
                    logger.info("atomicInteger6-{}", atomicInteger.get());
                }
            }).start();
        }
    }

}
